Use more precise return types in asyncio methods#6937
Merged
Akuli merged 1 commit intopython:masterfrom Jan 17, 2022
Merged
Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: websockets (https://github.com/aaugustin/websockets)
+ src/websockets/legacy/client.py:641: error: "_ProtocolT" has no attribute "close"
+ src/websockets/legacy/client.py:655: error: Incompatible types in assignment (expression has type "WebSocketClientProtocol", variable has type "_ProtocolT")
+ src/websockets/legacy/client.py:659: error: "_ProtocolT" has no attribute "handshake"
+ src/websockets/legacy/client.py:661: error: "_ProtocolT" has no attribute "origin"
+ src/websockets/legacy/client.py:662: error: "_ProtocolT" has no attribute "available_extensions"
+ src/websockets/legacy/client.py:663: error: "_ProtocolT" has no attribute "available_subprotocols"
+ src/websockets/legacy/client.py:664: error: "_ProtocolT" has no attribute "extra_headers"
+ src/websockets/legacy/client.py:667: error: "_ProtocolT" has no attribute "fail_connection"
+ src/websockets/legacy/client.py:668: error: "_ProtocolT" has no attribute "wait_closed"
+ src/websockets/legacy/client.py:672: error: Incompatible return value type (got "_ProtocolT", expected "WebSocketClientProtocol")
anyio (https://github.com/agronholm/anyio)
+ src/anyio/_backends/_asyncio.py:1365: error: Redundant cast to "StreamProtocol" [redundant-cast]
+ src/anyio/_backends/_asyncio.py:1555: error: Redundant cast to "DatagramProtocol" [redundant-cast]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/connector.py:1295: error: Redundant cast to "ResponseHandler" [redundant-cast]
|
srittau
approved these changes
Jan 17, 2022
Collaborator
srittau
left a comment
There was a problem hiding this comment.
LGTM, the anyio and aiohttp primer output looks promising. websockets is doing some complicated stuff when creating protocols, so I think they'd just need to update their annotations. I'd like a second opinion, though.
Collaborator
|
websockets does this: if kwargs.pop("unix", False):
...
create_connection = functools.partial(
loop.create_unix_connection, factory, path, **kwargs
)
else:
...
create_connection = functools.partial(
loop.create_connection, factory, host, port, **kwargs
)
...
self._create_connection = create_connectionCode like this isn't very typing friendly, and I don't think there's a good way for us to support it anyway. Websockets already has casts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.